<template>
  <div class="CustomerManage">
    <div class="search">
      <el-form :inline="true" :model="search" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input
            v-model="search.key"
            placeholder="请输入设备名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="输入时间">
          <el-date-picker
            v-model="search.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="chage"
          ></el-date-picker>
        </el-form-item>
        <el-form-item
          ><el-button type="primary" @click="onsubmit"
            >查询</el-button
          ></el-form-item
        >
      </el-form>
      <el-button class="ebtn" type="warning" @click="GotoPg(null, null)"
        >新增客户</el-button
      >
    </div>
    <el-table
      :data="ListData"
      stripe
      style=" margin: 10px 20px;width: calc(100% - 40px)"
      :height="autoHeightTable"
      show-overflow-tooltip
    >
      <el-table-column
        label="编号"
        align="center"
        prop="enterpriseNumber"
      ></el-table-column>
      <el-table-column
        label="企业名称"
        align="center"
        prop="enterpriseName"
      ></el-table-column>
      <el-table-column
        label="联系人"
        align="center"
        prop="contacts"
      ></el-table-column>
      <el-table-column
        label="联系方式"
        align="center"
        prop="contactsPhone"
      ></el-table-column>
      <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="primary"
            @click="GotoPg(scope.row.id, null)"
            >编辑</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="GotoPg(scope.row.id, 1)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :current-page="current"
      :page-size="pagesize"
      @current-change="handleCurrentChange"
      :page-count="total"
    >
    </el-pagination>

  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      search: { key: "", start: "", end: "" },
      ListData: [],
      total: 1,
      current: 1,
      pagesize: 10,
    };
  },
  computed: {
    autoHeightTable() {
      return document.documentElement.scrollHeight - 251 - 78;
    },
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      const json = {
        beginTime: this.search.start,
        endTime: this.search.end,
        key: this.search.key,
        pageNum: this.current,
        pageSize: this.pagesize,
      };
      const message = JSON.parse(localStorage.getItem("message"));
      axios
        .post(
          "/JX_java/sales/clientMessage/getUserClientList?userId=" + message.Id,
          json
        )
        .then((res) => {
          this.ListData = res.data.data.content;
          this.total= res.data.data.totalPages
        });
    },
    handleCurrentChange(e) {
      this.current = e;
      this.getList();
    },

    onsubmit() {
      this.getList();
      // this.LoadContents();
    },

    chage(e) {
      if (e) {
        this.search.start = e[0];
        this.search.end = e[1];
      } else {
        this.search.start = "";
        this.search.end = "";
      }
    },
    GotoPg(id, edit) {
      this.$router.push({
        path: "./CustomerManageAdd",
        query: { id: id, edit: edit },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/base.scss";
.CustomerManage .search {
  height: 50px;
  border-radius: 5px;
  background-color: #fff;
  padding-left: 20px;
  padding-top: 10px;
  margin: 0 20px ;
}
.CustomerManage .demo-form-inline {
  display: inline-block;
}
.CustomerManage .el-pagination {
  margin-top: 15px;
  text-align: center;
}
.CustomerManage .ebtn {
  float: right;
  margin-right: 20px;
}
</style>
